﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SportAnalyzer
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                

                this.Validate();

                SportAnalyzerDataSet.sportAnalyzerDocumentSession session = new SportAnalyzerDataSet.sportAnalyzerDocumentSession();
                session.id = generateID();
                session.type = cB_Type.Text;
                session.date = dateTimePicker1.Value.Date;
                //session.hrTime = DateTime.Parse(tB_hrTime.Text);
                //session.hrMax = Convert.ToInt32(tB_hrHrMax.Text);
                session.hrDist = Convert.ToDecimal(tB_hrDist.Text);
                //session.hrCal = Convert.ToInt32(tB_hrCal.Text);
                //session.hrAvg = Convert.ToInt32(tB_hrHrAvg.Text);
                //session.gpsTime = DateTime.Parse(tB_gpsTime.Text);
                //session.gpsDist = Convert.ToDecimal(tB_gpsDist.Text);
                //session.gpsCal = Convert.ToInt32(tB_gpsCal.Text);
                //session.bcTime = DateTime.Parse(tB_bcTime.Text);
                //session.bcDist = Convert.ToDecimal(tB_bcDist.Text);
                //session.bcCal = Convert.ToInt32(tB_bcCal.Text);
                //session.cadAvg = Convert.ToInt32(tB_hrCadAvg.Text);
                //session.cadMax = Convert.ToInt32(tB_hrCadMax.Text);

                Program.mainDocument.Items.Add(session);
                Program.mainDocument.SaveToFile("filename.xml");


                //sportAnalyzerDocumentSession session = new sportAnalyzerDocumentSession();
                //session.id = this.generateID();
                //session.date = String.Format("{0:yyyy-MM-dd}", this.dateTimePicker1.Value);
                //session.type = this.cB_Type.Text;

                //sportAnalyzerDocumentSessionHrMonitor hrMonitor = new sportAnalyzerDocumentSessionHrMonitor();
                //hrMonitor.distance = this.tB_hrDist.Text;
                //hrMonitor.time = this.tB_hrTime.Text;
                //hrMonitor.calories = this.tB_hrCal.Text;

                //sportAnalyzerDocumentSessionHrMonitorHR hr = new sportAnalyzerDocumentSessionHrMonitorHR();
                //hr.max = this.tB_hrHrMax.Text;
                //hr.avg = this.tB_hrHrAvg.Text;

                //sportAnalyzerDocumentSessionHrMonitorCad cad = new sportAnalyzerDocumentSessionHrMonitorCad();
                //cad.max = this.tB_hrCadMax.Text;
                //cad.avg = this.tB_hrCadAvg.Text;

                //hrMonitor.hr = hr;
                //hrMonitor.cad = cad;
                //session.hrMonitor.Add(hrMonitor);

                //sportAnalyzerDocumentSessionBikeComputer bikeComp = new sportAnalyzerDocumentSessionBikeComputer();
                //bikeComp.distance = this.tB_bcDist.Text;
                //bikeComp.time = this.tB_bcTime.Text;
                //bikeComp.calories = this.tB_bcCal.Text;

                //session.bikeComputer.Add(bikeComp);

                //sportAnalyzerDocumentSessionGps gpsData = new sportAnalyzerDocumentSessionGps();
                //gpsData.distance = this.tB_gpsDist.Text;
                //gpsData.time = this.tB_gpsTime.Text;
                //gpsData.calories = this.tB_gpsCal.Text;

                //session.gps.Add(gpsData);

                //Program.mainDocument.Items.Add(session);
                //Program.mainDocument.SaveToFile("filename.xml");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Source + ex.Message);
            }
            finally
            {
                this.Close();
            }
        }

        private string generateID()
        {
            string id;
            string datePart = String.Format("{0:yyyyMMdd}", this.dateTimePicker1.Value);
            string typePart = this.cB_Type.Text.Replace(" ", "");
            id = datePart + typePart.Trim();

            return id;
        }

    }
}
